package com.liangwj.springbootdesignpatterns.structureTypePatterns.filter.demo_2;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>Description:</b> 创建过滤器链 <br/>
 * @author Lingwenjun
 * @date 2019/1/24-18:34
 * @version 1.0
 */
public class FilterChain {

    private List<Filter> filters = new ArrayList<>();

    private Target target;

    public void addFilter(Filter filter) {
        filters.add(filter);
    }

    public void setTarget(Target target) {
        this.target = target;
    }

    public void execute(String request) {
        for (Filter filter : filters) {
            filter.execute(request);
        }
        target.execute(request);
    }
}
